package com.yy.try_;

import com.yy.exception_.NullPointerException_;

/**
 * chapter12  com.yy.try_
 * 2023-05-09 22:50
 *
 * @author yy yuyue
 * description : 不可描述
 * @date 2023/5/9 22:50
 */
public class TryCatchDetail02 {
    public static void main(String[] args) {

        //老师解读
        //1. 如果try代码块有可能有多个异常
        //2. 可以使用多个catch 分别捕获不同的异常, 相应处理
        //3. 要求子类异常写在前面, 父类异常写在后面
        try{
            Person person = new Person();
            person = null;
            System.out.println(person.getName());//NullPointerException
            int n1 = 10;
            int n2 = 0;
            int res = n1 / n2;//ArithmeticException
        }catch (NullPointerException e){
            System.out.println("空指针异常=" + e.getMessage());
        }catch (ArithmeticException e){
            System.out.println("算术异常=" + e.getMessage());
        }finally {
            System.out.println("finally代码块被执行...");
        }
    }
}

class Person{
    private String name = "qiucheng";
    public String getName(){
        return name;
    }
}